package com.yunfei.springbootgoods.controller;

import com.yunfei.springbootgoods.dto.Page;
import com.yunfei.springbootgoods.dto.Result;
import com.yunfei.springbootgoods.exception.MyException;
import com.yunfei.springbootgoods.exceptionEnums.ExceptionEnum;
import com.yunfei.springbootgoods.service.GoodsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class OrderController {

    @Autowired
    private GoodsOrderService goodsOrderService;

    @GetMapping(value = "/getGoodsOrderPage")
    public Result getGoodsOrderPage(Integer pageNo,Integer pageSize){

        try {
            Page goodsOrderPage = goodsOrderService.getGoodsOrderPage(pageNo, pageSize);
            Result result = new Result();
            result.setData(goodsOrderPage);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(ExceptionEnum.ERROR_ORDER_LIST);
        }
    }

    /**
     * 修改状态为已支付：1
     * @param orderId
     * @return
     */
    @GetMapping(value = "/updateGoodsOrder01")
    public Result updateGoodsOrder01(Integer orderId){
        try {
            goodsOrderService.updateGoodsOrder01(orderId);
            Result result = new Result();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(ExceptionEnum.ERROR_ORDER_UPDATE01);
        }

    }

    /**
     * 修改状态为已取消：0
     * @param orderId
     * @return
     */
    @GetMapping(value = "/updateGoodsOrder02")
    public Result updateGoodsOrder02(Integer orderId){
        try {
            goodsOrderService.updateGoodsOrder02(orderId);
            Result result = new Result();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException(ExceptionEnum.ERROR_ORDER_UPDATE02);
        }

    }




}
